#include "wtlpch.h"

#include "resource.h"
#include "TreeDownCatalog.h"

#define MAX_DOWNCAT_TEXT		64

#define CAT_ICON_TITLE_INDEX		0
#define CAT_ICON_DOWNLOAD_INDEX		1
#define CAT_ICON_FINISH_INDEX		2
#define CAT_ICON_VIDEO_INDEX		3
#define CAT_ICON_MUSIC_INDEX		4
#define CAT_ICON_ZIP_INDEX			5
#define CAT_ICON_OTHER_INDEX		6

CTreeDownCatalog::CTreeDownCatalog(void)
{
	m_imglstDownCatlog.Create(16, 16, ILC_COLOR32, DOWNLOAD_CAT_NUM, 0);

	//Load catalog icons to imagelist
	CIconHandle hCatIcon;

	//Load Icon From resource
	m_imglstDownCatlog.AddIcon(hCatIcon.LoadIconW(IDR_MAINFRAME));			hCatIcon.Detach();

	m_imglstDownCatlog.AddIcon(hCatIcon.LoadIconW(IDI_DOWNCAT_DOWNLOAD));	hCatIcon.Detach();
	m_imglstDownCatlog.AddIcon(hCatIcon.LoadIconW(IDI_DOWNCAT_FINISH));		hCatIcon.Detach();
	m_imglstDownCatlog.AddIcon(hCatIcon.LoadIconW(IDI_DOWNCAT_VIDEO));		hCatIcon.Detach();
	m_imglstDownCatlog.AddIcon(hCatIcon.LoadIconW(IDI_DOWNCAT_MUSIC));		hCatIcon.Detach();
	m_imglstDownCatlog.AddIcon(hCatIcon.LoadIconW(IDI_DOWNCAT_ZIP));		hCatIcon.Detach();
	m_imglstDownCatlog.AddIcon(hCatIcon.LoadIconW(IDI_DOWNCAT_OTHER));		hCatIcon.Detach();
}

CTreeDownCatalog::~CTreeDownCatalog(void)
{
	//It's Sure that the imagelist contains icons
	m_imglstDownCatlog.Destroy();
}

void CTreeDownCatalog::AddCatItem()
{
	SetImageList(m_imglstDownCatlog, TVSIL_NORMAL);

	//Buffer for Option text
	WCHAR* lpwstrCatText = new WCHAR[MAX_DOWNCAT_TEXT];

	//Set Root title
	::wmemset(lpwstrCatText, 0, MAX_DOWNCAT_TEXT);
	::LoadStringW(::GetModuleHandle(NULL), IDS_TA_DOWNCAT_TITLE, lpwstrCatText, MAX_DOWNCAT_TEXT);

	CTreeItem tiRootItem = InsertItem(lpwstrCatText, TVI_ROOT, TVI_LAST);
	tiRootItem.SetImage(CAT_ICON_TITLE_INDEX, CAT_ICON_TITLE_INDEX);

	//Set Download Catalog
	::wmemset(lpwstrCatText, 0, MAX_DOWNCAT_TEXT);
	::LoadStringW(::GetModuleHandle(NULL), IDS_TA_DOWNCAT_DOWNLOAD, lpwstrCatText, MAX_DOWNCAT_TEXT);

	CTreeItem tiDownCat = InsertItem(lpwstrCatText, tiRootItem, TVI_LAST);
	tiDownCat.SetImage(CAT_ICON_DOWNLOAD_INDEX, CAT_ICON_DOWNLOAD_INDEX);

	//Set Finished Catalog
	::wmemset(lpwstrCatText, 0, MAX_DOWNCAT_TEXT);
	::LoadStringW(::GetModuleHandle(NULL), IDS_TA_DOWNCAT_DOWNLOADED, lpwstrCatText, MAX_DOWNCAT_TEXT);

	CTreeItem tiFinishedCat = InsertItem(lpwstrCatText, tiRootItem, TVI_LAST);
	tiFinishedCat.SetImage(CAT_ICON_FINISH_INDEX, CAT_ICON_FINISH_INDEX);

	//Set Finished Catalog Video
	::wmemset(lpwstrCatText, 0, MAX_DOWNCAT_TEXT);
	::LoadStringW(::GetModuleHandle(NULL), IDS_TA_DOWNCAT_DOWNLOADED_VIDEO, lpwstrCatText, MAX_DOWNCAT_TEXT);

	CTreeItem tiFinishedVideo = tiFinishedCat.AddTail(lpwstrCatText, CAT_ICON_VIDEO_INDEX);

	//Set Finished Catalog Music
	::wmemset(lpwstrCatText, 0, MAX_DOWNCAT_TEXT);
	::LoadStringW(::GetModuleHandle(NULL), IDS_TA_DOWNCAT_DOWNLOADED_MUSIC, lpwstrCatText, MAX_DOWNCAT_TEXT);

	CTreeItem tiFinishedMusic = tiFinishedCat.AddTail(lpwstrCatText, CAT_ICON_MUSIC_INDEX);

	//Set Finished Catalog zip
	::wmemset(lpwstrCatText, 0, MAX_DOWNCAT_TEXT);
	::LoadStringW(::GetModuleHandle(NULL), IDS_TA_DOWNCAT_DOWNLOADED_ARCHIVE, lpwstrCatText, MAX_DOWNCAT_TEXT);

	CTreeItem tiFinishedZip = tiFinishedCat.AddTail(lpwstrCatText, CAT_ICON_ZIP_INDEX);

	//Set Finished Catalog Other
	::wmemset(lpwstrCatText, 0, MAX_DOWNCAT_TEXT);
	::LoadStringW(::GetModuleHandle(NULL), IDS_TA_DOWNCAT_DOWNLOADED_OTHER, lpwstrCatText, MAX_DOWNCAT_TEXT);

	CTreeItem tiFinishedOther = tiFinishedCat.AddTail(lpwstrCatText, CAT_ICON_OTHER_INDEX);

	//Expand Tree
	Expand(tiRootItem);
	Expand(tiFinishedCat);
}

LRESULT CTreeDownCatalog::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{

	bHandled = FALSE;
	return S_OK;
}
